package com.dashboard.cloud.provider.service;

import com.dashboard.cloud.common.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: spring-cloud-dashboard
 * @Package: com.dashboard.cloud.provider.service
 * @ClassName: RemoteServerService
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/15 11:36
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Slf4j
@Service
public class RemoteServerService {

    public String running() {
        return "nacos remote server is running ...";
    }

    // -------------------------------------------------------------
    public UserDTO queryUserByPrimary(Long userId) {
        long startTime = System.currentTimeMillis();
        try {
            Thread.sleep(59990);
            return UserDTO.findAll().stream()//
                    .filter(u -> Objects.equals(userId, u.getUserId())).findAny()//
                    .orElseThrow(() -> new NoSuchElementException(""));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            log.info("server method spend time: {}" ,(System.currentTimeMillis() - startTime) / 1000 + "s");
        }
    }
}